package com.bw.module_motorcircle.test_recyclerview

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_motorcircle.R

class TestActivity : AppCompatActivity() {
    private lateinit var rv:RecyclerView
    private lateinit var adapter:MyAdapter
    private val mList = ArrayList<MyModel>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_test)
        rv = findViewById(R.id.rv)
        adapter = MyAdapter()
        rv.adapter = adapter
        rv.layoutManager = LinearLayoutManager(this)

        for (i in 0..100){
            val myModel = MyModel(i,"title"+i,"https://ts1.tc.mm.bing.net/th/id/R-C.98411f1b4f70501fbfa652c4c2a63843?rik=BI5K%2bIqMmK3d5g&riu=http%3a%2f%2fimg.ewang.com%2f6c117a240949949b1c6c.jpg&ehk=g9TE7x8dPR2TpuAjguBK7KayNfHi0eI2GY%2bn7SEEzPE%3d&risl=&pid=ImgRaw&r=0")
            mList.add(myModel)
        }
        adapter.setData(mList)

        //优化方案一
        val pool = RecyclerView.RecycledViewPool()
        pool.setMaxRecycledViews(0,10)
        pool.setMaxRecycledViews(1,10)
        rv.setItemViewCacheSize(10)
        rv.setRecycledViewPool(pool)


    }

    fun remove(view: View) {
        adapter.removeData(1)
    }
    fun add(view: View) {
        val mList = ArrayList<MyModel>()
        for (i in 101..105){
            val myModel = MyModel(i,"title"+i,"https://ts1.tc.mm.bing.net/th/id/R-C.98411f1b4f70501fbfa652c4c2a63843?rik=BI5K%2bIqMmK3d5g&riu=http%3a%2f%2fimg.ewang.com%2f6c117a240949949b1c6c.jpg&ehk=g9TE7x8dPR2TpuAjguBK7KayNfHi0eI2GY%2bn7SEEzPE%3d&risl=&pid=ImgRaw&r=0")
            mList.add(myModel)
        }
        adapter.addData(mList)
    }

    fun update(view: View) {
//        adapter.update(1)
        adapter.updateLike(1)

    }
}